package helloWorld;

import org.mt4j.MTApplication;
import org.mt4j.components.MTCanvas;
import org.mt4j.components.interfaces.IMTComponent3D;
import org.mt4j.components.visibleComponents.shapes.MTRectangle;
import org.mt4j.input.inputProcessors.IGestureEventListener;
import org.mt4j.input.inputProcessors.MTGestureEvent;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapEvent;
import org.mt4j.input.inputProcessors.componentProcessors.zoomProcessor.ZoomEvent;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;


public class LetterGestureListener implements IGestureEventListener {
	private MTApplication mtApplication;
	private Controller controller;
	public LetterGestureListener(MTApplication mtApplication){
		this.mtApplication = mtApplication;
		controller = Controller.getInstance();
	}

	@Override
	public boolean processGestureEvent(MTGestureEvent ge) {
		if(ge instanceof TapEvent){
			TapEvent te = (TapEvent)ge;
			IMTComponent3D target = te.getTargetComponent();
			if(target instanceof Letter){
				Letter letter = (Letter)te.getTargetComponent();
				System.out.println("Change to letter" + letter.getLetter());
				controller.setCurrentLetter(letter.getLetter());
				mtApplication.changeScene(mtApplication.getScene("ArtistScene"));
			}
			else if (target instanceof MTRectangle) {
				MTRectangle rectangle = (MTRectangle) target;
				switch (te.getTapID()) {
				case TapEvent.BUTTON_DOWN:
					System.out.println("Button down state on " + target);
					rectangle.setFillColor(new MTColor(200,100,100));
					break;
				case TapEvent.BUTTON_UP:
					System.out.println("Button up state on " + target);
					rectangle.setFillColor(new MTColor(255,255,255));
					break;
				case TapEvent.BUTTON_CLICKED:
					System.out.println("Button clicked state on " + target);
					rectangle.setFillColor(new MTColor(255,255,255));
					break;
				default:
					break;
				}
			}else if(target instanceof MTCanvas){
				MTCanvas rectangle = (MTCanvas) target;
				switch (te.getTapID()) {
				case TapEvent.BUTTON_DOWN:
					System.out.println("Button down state on " + target);
					float curX = te.getCursor().getCurrentEvtPosX();
					float curY = te.getCursor().getCurrentEvtPosY();
					Vector3D origin = target.getViewingCamera().getPosition();
					System.out.println("Current cam position: \n" + origin.getX() +
							"\n" + origin.getY() + "\n" + origin.getZ());
					
					//target.getViewingCamera().setPosition(new Vector3D(curX,curY));
					break;
				case TapEvent.BUTTON_UP:
					System.out.println("Button up state on " + target);
					
					break;
				case TapEvent.BUTTON_CLICKED:
					System.out.println("Button clicked state on " + target);
					
					break;
				default:
					break;
				}
			}
		} else if (ge instanceof ZoomEvent){
			ZoomEvent ze = (ZoomEvent)ge;
			
			
		}
		return false;

	}
	
	
}
